#ifndef __MCWIDGET_HH__
#define __MCWIDGET_HH__

#include <opengl/window.h>
#include <opengl/texture.h>
#include <opengl/camera.h>
#include <mc/chunk.h>
#include <mc/world.h>
#include <mc/loader.h>
#include <mc/player.h>
#include <mc/block.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <string>
#include <vector>
#include <map>

namespace mc
{

class MCWidget : public opengl::Window
{
public:
    MCWidget(int widget, int height, const std::string& filename);
    virtual ~MCWidget() noexcept override;

private:
    //! @brief 渲染函数
    virtual void render() override;

    //! @brief 程序输入控制
    virtual void processInput() override;

    //! @brief 更新视口大小回调函数
    virtual void framebufferSizeCallback(GLFWwindow* window, int width, int height) override;

    //! @brief 鼠标移动回调
    virtual void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) override;

    //! @brief 鼠标滚轮回调
    virtual void scrollCallback(GLFWwindow* window, double xoffset, double yoffset) override;

    //! @brief 鼠标点击回调
    virtual void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods) override;

    //! @brief 键盘输入回调
    virtual void keyboardCallback(GLFWwindow* window, int key, int scancode, int action, int mods) override;

    //! @brief 运行帧计算
    void calFrameTime();

    //! @brief 初始化游戏
    void initGame(const std::string& filename);

    //! @brief 释放资源
    virtual void freeResources() override;

private:
    //! @brief 世界
    World* _world;
    Loader* _loader;

    //! @brief 玩家
    Player* _player;

    //! @brief 程序帧信息计算
    float _deltaTime;
    float _lastFrame;
    float _lastX;
    float _lastY;
    bool _firstMouse;
};

}

#endif